package com.ylx.web.p;

import com.ylx.pojo.Cart;
import com.ylx.pojo.CartItem;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

@WebServlet("/updateBuyNumServlet")
public class UpdateBuyNumServlet extends HttpServlet {
    protected void doPost (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String id = request.getParameter("id");
        String buyNum = request.getParameter("buyNum");
        int i = Integer.parseInt(buyNum);

        HttpSession session = request.getSession();
        Cart cart = (Cart)session.getAttribute("cart");

        Map<String, CartItem> map=cart.getCartItems();

          map.get(id).setBuyNum(i);
          response.sendRedirect("front/cart.jsp ");






    }

    protected void doGet (HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        this.doPost(request, response);

    }
}
